﻿using BCGM.MedicalWisdom.IServices;
using BCGM.MedicalWisdom.Model;
using BCGM.MedicalWisdom.Model.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace BCGM.MedicalWisdom.Api.Controllers
{
	[Route("api/[controller]/[action]")]
	[ApiController]
    [Authorize(Permissions.Name)]
     public class DoctorGradeController : ControllerBase
    {
            /// <summary>
            /// 服务器接口，因为是模板生成，所以首字母是大写的，自己可以重构下
            /// </summary>
            private readonly IDoctorGradeServices _doctorGradeServices;
    
            public DoctorGradeController(IDoctorGradeServices DoctorGradeServices)
            {
                _doctorGradeServices = DoctorGradeServices;
            }
    
            [HttpGet]
            public async Task<MessageModel<PageModel<DoctorGrade>>> Get(int page = 1, string key = "",int intPageSize = 50)
            {
                if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
                {
                    key = "";
                }
    
                Expression<Func<DoctorGrade, bool>> whereExpression = a => true;
    
                return new MessageModel<PageModel<DoctorGrade>>()
                {
                    msg = "获取成功",
                    success = true,
                    response = await _doctorGradeServices.QueryPage(whereExpression, page, intPageSize)
                };

            }

            [HttpGet("{id}")]
            public async Task<MessageModel<DoctorGrade>> Get(string id)
            {
                return new MessageModel<DoctorGrade>()
                {
                    msg = "获取成功",
                    success = true,
                    response = await _doctorGradeServices.QueryById(id)
                };
            }

            [HttpPost]
            public async Task<MessageModel<string>> Post([FromBody] DoctorGrade request)
            {
                var data = new MessageModel<string>();

                var id = await _doctorGradeServices.Add(request);
                data.success = id > 0;
                if (data.success)
                {
                    data.response = id.ObjToString();
                    data.msg = "添加成功";
                } 

                return data;
            }

            //[HttpPut]
            //public async Task<MessageModel<string>> Put([FromBody] DoctorGrade request)
            //{
            //    var data = new MessageModel<string>();
            //    data.success = await _doctorGradeServices.Update(request);
            //    if (data.success)
            //    {
            //        data.msg = "更新成功";
            //        data.response = request?.id.ObjToString();
            //    }

            //    return data;
            //}

            //[HttpDelete]
            //public async Task<MessageModel<string>> Delete(int id)
            //{
            //    var data = new MessageModel<string>();
            //    var model = await _doctorGradeServices.QueryById(id);
            //    model.IsDeleted = true;
            //    data.success = await _departmentServices.Update(model);
            //    if (data.success)
            //    {
            //        data.msg = "删除成功";
            //        data.response = model?.Id.ObjToString();
            //    }

            //    return data;
            //}
    }
}